<!-- -->
<template>
  <div class="container">
    <center>
    <div>
      <h2>订单查看</h2>
    </div>
    <!-- 表格渲染 -->
    <el-table
      border
      :fit="true"
      ref="tableData"
      max-height="750"
      style="width: 100%"
      :data="tableData"

    >
      <el-table-column type="index" label="序号" width="60"></el-table-column>
      <el-table-column prop="u_id" v-if="false"></el-table-column>
      <el-table-column prop="order_id" label="订单号"></el-table-column>
      <el-table-column prop="roomNumber" label="订单房间数"></el-table-column>
      <el-table-column prop="orderStatus" label="状态" :formatter="orderStatus"></el-table-column>
      <el-table-column prop="orderTime" label="订单时间" width="160"></el-table-column>
      <el-table-column prop="arrireDate" label="到达时间" width="160"></el-table-column>
      <el-table-column prop="leaveDate" label="离开时间" width="160"></el-table-column>
      <el-table-column prop="orderMoney" label="定价（元）"></el-table-column>
      <el-table-column prop="userPhone" label="手机号" width="170"></el-table-column>
      <el-table-column prop="user_remark" label="用户备注"></el-table-column>
      <el-table-column prop="admin_remark" label="备注"></el-table-column>
      <el-table-column fixed="right" label="操作" width="160">
        <template slot-scope="scope">
          <el-button
            size="medium"
            type="text"
            @click="orderCancelByUser(scope.$index,scope.row)"
            :disabled="scope.row.orderStatus!=0"
          >退订</el-button>
          <el-button
            size="medium"
            type="text"
            @click="deleteOrder(scope.$index,scope.row)"
            :disabled="scope.row.orderStatus!=-1&&scope.row.orderStatus!=-2&&scope.row.orderStatus!=3"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    </center>

</div>

</template>

<script>
export default {
  name: "OrderChange",
    data(){
    return{
        tableData: [],
        u_id:'',
        roomInfo:{
          order_id:'',
        }

    }
  },
  mounted () {
    this.u_id = this.$store.getters.getUID
    this.getHome()
  },
  methods:{
      orderStatus(row) {
          console.log(row);
          if (row.orderStatus == 0) {
              row.Status = "未审核";
              return row.Status;
          } else if (row.orderStatus == 1) {
              row.Status = "审核通过";
              return row.Status;
          } else if (row.orderStatus == 2) {
              row.Status = "已入住";
              return row.Status;
          } else if (row.orderStatus == -1) {
              row.Status = "用户取消订单";
              return row.Status;
          } else if (row.orderStatus == -2) {
              row.Status = "拒绝";
              return row.Status;
          }
      },
    getHome(){
      this.$axios.post("/ssms/common/allOrdersByU_id",{headers:{'Content-Type':'application/json',
      responseType: "application/json"}})
      .then(res => {
        console.log(res.data);
        if(res.data.code === 0){
          this.tableData = res.data.obj;

        }
      })
  },
  deleteOrder(index,row){
    this.roomInfo.order_id = row.order_id;
    var data = this.roomInfo;
    this.$axios.get("/ssms/common/deleteOrder", {params:{order_id:this.roomInfo.order_id}}, {headers:{'Content-Type':'application/json',
      responseType: "application/json"}})
      .then(res => {
        console.log(res.data);
        if(res.data.code === 0){
          alert("删除订单成功")
        }else{
          alert(res.msg);
        }
      })
  },
  orderCancelByUser(index,row){
    this.roomInfo.order_id = row.order_id;
    var data = this.roomInfo;
    this.$axios.get("/ssms/common/orderCancelByUser", {params:{order_id:this.roomInfo.order_id}},{headers:{'Content-Type':'application/json',
      responseType: "application/json"}})
      .then(res => {
        console.log(res.data);
        if(res.data.code === 0){
          alert("退订成功");

        }else{
          alert(res.msg);
        }
      })
  }
  },

  components: {},

  filters: {},

  computed: {},
  };
</script>
<style scoped>
</style>
